#ifndef MESH_FACTORY
#define MESH_FACTORY
#include "Export.h"
#include <iostream>
#include "ILoader.h"
#include "LoaderOFF.h"
#include "LoaderOBJ.h"
#include "LoaderMNT.h"

namespace glow
{
class SHARED MeshFactory
{
	public :
		Mesh_data * getMesh(std::string filename)
		{
			size_t ext_pos = filename.find_last_of('.');
			if( ext_pos != string::npos )
				std::string ext1 = filename.substr( ext_pos );
			else
			{
				std::cout<<"404 : Extension not Found"<<std::endl;
				return NULL;
			}
			try
			{
				return TheMap[ext1]::load(filename);
			}catch(exception e){
				std::cout<<"Extension not supported"<<std::endl;
				return NULL;
			}
		}
		
	private :
	static map<string,ILoader<Mesh_data> *> TheMap;
};
static map<string,ILoader<Mesh_data> *> TheMap;

class SHARED MeshFactoryBuilder
{
	friend class MeshFactory;
public :

	MeshFactoryBuilder()
	{
	MeshFactory::TheMap["off"]= new LoaderOFF;
	MeshFactory::TheMap["mnt"]= new LoaderMNT;
	MeshFactory::TheMap["obj"]= new LoaderOBJ;
	}
		
};
static MeshFactoryBuilder TheMeshFactoryBuilder;
}

#endif
